/**
 * Copyright 2008 Wink Saville
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

if (typeof LinkList == "undefined")
{
	function LinkList()
	{
		this.head = null;
		this.tail = null;
	}

	LinkList.prototype.isEmpty = function ()
	{
		return this.head == null;
	}

	LinkList.prototype.isNotEmpty = function ()
	{
		return this.head != null;
	}

	LinkList.prototype.push = function (node)
	{
		if ((node == null) || (typeof node != "object"))
			return null;

		node.next = this.head;	
		this.head = node;
		if (node.next == null)
		{
			this.tail = node;
		}
			
		return node;
	}

	LinkList.prototype.pop = function ()
	{
		var node = this.head;
		if (node != null)
		{
			this.head = node.next;
			node.next = null;
			if (this.head == null)
			{
				this.tail = null;
			}
		}
			
		return node;
	}

	LinkList.prototype.append = function (node)
	{
		if ((node == null) || (typeof node != "object"))
			return null;

		node.next = null;
		if (this.tail == null)
		{
			this.head = node;
		}
		else
		{
			this.tail.next = node;
		}
		this.tail = node;

		return node;
	}
}

